import 'package:flutter/material.dart';

import '../utils/httputils/urlpath.dart';
import '../utils/util.dart';

extension GetNavigationEx on GetInterface {
  ///find拓展，未注册时为空
  S? findOr<S>({String? tag}) {
    if (Get.isRegistered<S>(tag: tag)) {
      return Get.find<S>(tag: tag);
    }
    return null;
  }

  ///延迟返回
  void backDelay<T>({
    T? result,
    bool closeOverlays = false,
    bool canPop = true,
    int? id,
  }) async {
    await Future.delayed(const Duration(milliseconds: 800));
    back(
      result: result,
      closeOverlays: closeOverlays,
      canPop: canPop,
      id: id,
    );
  }

  //用户协议
  Future<T?>? toAgreeAssessment<T>() async {
    return await toNamed(RouterPath.web_view, parameters: {
      'url': UrlPath.agreeAssessment,
      'title': Ls.yonghuxieyi,
      'safeArea': '1',
    });
  }

// 隐私政策
  Future<T?>? toAgreePrivacy<T>() async {
    return await toNamed(RouterPath.web_view, parameters: {
      'url': UrlPath.agreePrivacy,
      'title': Ls.yinsixieyi,
      'safeArea': '1',
    });
  }

  Future<T?>? toWeb<T>({
    required String url,
    String? title,
  }) async {
    return await Get.toNamed(RouterPath.web_view, parameters: {
      'url': url,
      'title': title ?? '',
    });
  }
}
